<#include "/@inc/funcMacros.ftl">
<#include "/@inc/copyright.txt">
<#assign className = TriaGram + "E" + Prefix + LateType>
<#assign intfName = TriaGram + "I" + Prefix + LateType>
<#assign baseName = TriaGram + Prefix >
<@pp.renameOutputFile name=className+".cpp">
</@pp.renameOutputFile>
//===============================================================================
//
// ${className}.cpp
// Provide implementation to interface
//      ${intfName}
//===============================================================================
//  ${Month} ${Year}  Creation: Code generated by the CAA wizard  ${Author}
//===============================================================================

// Local Framework
#include "${className}.h"

#include "${TriaGram}UtlMacros.h"

//KnowledgeInterfaces
#include "CATICkeParm.h"

// ObjectSpecsModeler Framework
#include "CATISpecObject.h"
#include "CATISpecAttrAccess.h"
#include "CATISpecAttrKey.h"

// System Framework
#include "CATMsgCatalog.h"

<@CAA_INCLUDE_HEADERS Attributes />

CATImplementClass ( ${className} ,
					DataExtension       ,
					${baseName}AttrAccess ,
					${baseName}${LateType}  );

//-------------------------------------------------------------------------------------
// ${className} : constructor
//-------------------------------------------------------------------------------------
${className}::${className}():
${baseName}AttrAccess()
{

}

//-------------------------------------------------------------------------------------
// ${className} : destructor
//-------------------------------------------------------------------------------------
${className}::~${className}()
{

}

// Tie the implementation to its interface
// ---------------------------------------

#include "TIE_${intfName}.h"
TIE_${intfName}( ${className});


<#list Attributes as attrib>  <#t>

<#switch attrib.type>

<#case ""><#t>
HRESULT ${className}::${attrib.name}()
{
	HRESULT rc = S_OK ;

	return rc ;
}
<#break>
<#case "tk_component"><#t>
<#case "tk_specobject"><#t>
HRESULT ${className}::Get${attrib.name}( CATISpecObject_var   &     ospSpec${attrib.name} )
{
	HRESULT rc = S_OK ;
    GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	 ospSpec${attrib.name} = spiSpecAttrAccess->GetSpecObject(piSpecAttrKey);

	 ${TriaGram}UtlReleasePtr(piSpecAttrKey);

	 return rc ;
}

HRESULT ${className}::Set${attrib.name}(  CATISpecObject   * ipSpec${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	if( ipSpec${attrib.name} )
	{
		CATISpecObject_var   spSpec${attrib.name} =  ipSpec${attrib.name} ;
		spiSpecAttrAccess->SetSpecObject(piSpecAttrKey, spSpec${attrib.name});
	}
	else
	{
		// The input ${attrib.name} pointer is null
		spiSpecAttrAccess->UnsetAttributeValue (piSpecAttrKey);
	}

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return S_OK ;
}
<#break>
<#case "tk_string"><#t>
HRESULT ${className}::Get${attrib.name}( CATUnicodeString   &  oStr${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	oStr${attrib.name} = spiSpecAttrAccess->GetString(piSpecAttrKey);

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( const CATUnicodeString   &  iStr${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetString(piSpecAttrKey, iStr${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break>
<#case "tk_boolean"><#t>
HRESULT ${className}::Get${attrib.name}( CATBoolean   &     ob${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	ob${attrib.name} = spiSpecAttrAccess->GetBoolean(piSpecAttrKey);

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( CATBoolean   ib${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetBoolean(piSpecAttrKey, ib${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break>
<#case "tk_integer"><#t>
HRESULT ${className}::Get${attrib.name}( int   &  on${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	on${attrib.name} = spiSpecAttrAccess->GetInteger(piSpecAttrKey);

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( int   in${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetInteger(piSpecAttrKey, in${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break><#t>
<#case "tk_double"><#t>
HRESULT ${className}::Get${attrib.name}( double   &     od${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	od${attrib.name} = spiSpecAttrAccess->GetDouble(piSpecAttrKey);

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( double   id${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetDouble(piSpecAttrKey, id${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break><#t>
<#case "tklist_double"><#t>
HRESULT ${className}::Get${attrib.name}( CATListOfDouble   &     oList${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	CATListOfDouble *pList = spiSpecAttrAccess->GetListDouble(piSpecAttrKey);
	if(pList )
		oList${attrib.name} = *pList ;

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( const CATListOfDouble   &     iList${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetListDouble(piSpecAttrKey, iList${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break>
<#case "tklist_integer"><#t>
HRESULT ${className}::Get${attrib.name}( CATListOfInt   &     oList${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	CATListOfInt *pList = spiSpecAttrAccess->GetListInteger(piSpecAttrKey);
	if(pList )
		oList${attrib.name} = *pList ;

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( const CATListOfInt   &     iList${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetListInteger(piSpecAttrKey, iList${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break>
<#case "tklist_string"><#t>
HRESULT ${className}::Get${attrib.name}( CATListOfCATUnicodeString   &     oList${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	CATListOfCATUnicodeString *pList = spiSpecAttrAccess->GetListString(piSpecAttrKey);
	if(pList )
		oList${attrib.name} = *pList ;

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Set${attrib.name}( const CATListOfCATUnicodeString   &     iList${attrib.name} )
{
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetListString(piSpecAttrKey, iList${attrib.name});

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  return S_OK ;
}
<#break>
<#case "tklist_component">
<#case "tklist_specobject">
HRESULT ${className}::Get${attrib.name}( CATListValCATISpecObject_var   &     oList${attrib.name} )
{
	oList${attrib.name}.RemoveAll() ;

	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	int nSize = spiSpecAttrAccess->GetListSize( piSpecAttrKey ) ;
	for(int i =1 ; i <= nSize; i++)
	{
		 oList${attrib.name}.Append ( spiSpecAttrAccess->GetSpecObject(piSpecAttrKey, i) ) ;
	}

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

   return rc ;
}

HRESULT ${className}::Set${attrib.name}( const CATListValCATISpecObject_var   &    iList${attrib.name} )
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	int nSize =  iList${attrib.name}.Size( ) ;
	for(int i =1 ; i <= nSize; i++)
	{
		spiSpecAttrAccess->SetSpecObject( piSpecAttrKey, iList${attrib.name}[i] , i ) ;
	}

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

   	return rc ;
}

HRESULT ${className}::Add${attrib.name}( const CATISpecObject_var  & ispSpec${attrib.name} , int	iIndex)
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	spiSpecAttrAccess->SetSpecObject(piSpecAttrKey, ispSpec${attrib.name}, iIndex);

	${TriaGram}UtlReleasePtr(piSpecAttrKey);

	return rc ;
}

HRESULT ${className}::Remove${attrib.name}( const CATISpecObject_var   & ispSpec${attrib.name})
{
	HRESULT rc = S_OK ;
	GET_SPEC_ATTR_ACCESS("${baseName}${attrib.name}") ;

	if(NULL_var == ispSpec${attrib.name})
	{
		spiSpecAttrAccess->RemoveAll(piSpecAttrKey) ;
	}
	else
	{
		  spiSpecAttrAccess->RemoveSpecObject(piSpecAttrKey, ispSpec${attrib.name} );
	}

  	${TriaGram}UtlReleasePtr(piSpecAttrKey);

  	return S_OK ;
}
<#break>
<#default><#t>
//-----------------------------------------------------------------------------
// Implements ${intfName}::Get${attrib.name}
//-----------------------------------------------------------------------------
HRESULT ${className}::Get${attrib.name} (CATICkeParm_var &  ospParm${attrib.name})
{
	HRESULT hr = GetParamAttr("${baseName}${attrib.name}", ospParm${attrib.name});

    return hr;
}

<#list ckeParam as parm>
<#if parm.tk_type == attrib.type> <#assign cke = parm> <#break></#if>
</#list>
//-----------------------------------------------------------------------------
// Implements ${intfName}::Get${attrib.name}
//-----------------------------------------------------------------------------
HRESULT ${className}::Get${attrib.name} (${cke.type} & o${attrib.name})
{
	CATICkeParm_var spiParm ;
	HRESULT hr = Get${attrib.name}(spiParm);
	if (FAILED(hr) || NULL_var == spiParm)
		return E_FAIL;

	<#if (cke.conversion?length > 1) >
	o${attrib.name} = ${cke.conversion} * GetValue(spiParm);
	<#else >
	o${attrib.name} = GetValue(spiParm);
	</#if>

    return hr;
}

//-----------------------------------------------------------------------------
// Implements ${intfName}::Set${attrib.name}
//-----------------------------------------------------------------------------
HRESULT ${className}::Set${attrib.name} ( ${cke.qual} ${cke.type} ${cke.setPrefix} i${attrib.name} )
{
    HRESULT hr = E_FAIL ;

	<#if (cke.conversion?length > 1) >
	i${attrib.name} /= ${cke.conversion} ; // Convert to MKS System
	</#if>

	CATICkeParm_var spiParm ;
	hr = Get${attrib.name}(spiParm);
	if (NULL_var == spiParm)
	{
        <#assign params = "NULL">
        <#if (attrib.data?size > 1) >
        double dParams[]= {${attrib.data[1]}, ${attrib.data[2]}, ${attrib.data[3]} } ;
        <#assign params = "dParams" >
        </#if>
		CATUnicodeString strName = CATMsgCatalog::BuildMessage("${TriaGram}${Catalog.name}NLS", "${baseName}${LateType}.${attrib.name}.Title");
        hr = CreateParam(${cke.arg}, strName, &i${attrib.name}, ${params}, spiParm) ;
		if( !spiParm )
			return E_FAIL;

		CATISpecObject_var spiSpecOnParm = spiParm ;

		hr = SetSpecAttr("${baseName}${attrib.name}", spiSpecOnParm);
	}
    else
    {
        spiParm->Valuate(i${attrib.name});
    }

	return hr;
}

<#break>

</#switch>
</#list>


